#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
int check(vector<vector<int>>& arr, vector<int> point, int size){
int y=point[0], x=point[1];
int crt=arr[y][x];
if(crt==-1) return -1;
for(int i=0; i<size; ++i){
for(int j=0; j<size; ++j){
if(arr[y+i][x+j]!=crt) return -1;
}
}
for(int i=0; i<size; ++i){
for(int j=0; j<size; ++j){
arr[y+i][x+j]=-1;
}
}
return crt;
}
vector<int> solution(vector<vector<int>> arr, size_t arr_rows, size_t arr_cols){
vector<int> answer={0, 0};
assert(arr_rows==arr_cols);
int zero=0, one=0, crt;
int n=arr_rows;
while(n!=1){
n/=2;
for(int i=0; i<arr_rows; i+=n){
for(int j=0; j<arr_cols; j+=n){
vector<int> point={i, j};
crt=check(arr, point, n);
if(crt==0) zero++;
if(crt==1) one++;
}
}
}
for(int i=0; i<arr_rows; ++i){
for(int j=0; j<arr_cols; ++j){
if(arr[i][j]==0) zero++;
else if(arr[i][j]==1) one++;
}
}
answer[0]=zero; answer[1]=one;
return answer;
}
int main(void){
vector<vector<int>> arr1={
{1, 1, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 1},
{1, 1, 1, 1}
};
vector<vector<int>> arr2={
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1},
{0, 1, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 1, 0, 0, 1},
{0, 0, 0, 0, 1, 1, 1, 1}
};
vector<int> result1=solution(arr1, arr1.size(), arr1[0].size());
vector<int> result2=solution(arr2, arr2.size(), arr2[0].size());
std::cout<<"result1: {"<<result1[0]<<", "<<result1[1]<<"}"<<std::endl;
std::cout<<"result2: {"<<result2[0]<<", "<<result2[1]<<"}"<<std::endl;
return 0;
}